const { DataTypes } = require('sequelize');
const sequelize = require('../config/database');

const WechatApp = sequelize.define('WechatApp', {
  id: {
    type: DataTypes.UUID,
    defaultValue: DataTypes.UUIDV4,
    primaryKey: true
  },
  name: {
    type: DataTypes.STRING,
    allowNull: false,
    comment: '应用名称'
  },
  app_id: {
    type: DataTypes.STRING,
    allowNull: false,
    unique: true,
    comment: '应用ID'
  },
  app_secret: {
    type: DataTypes.STRING,
    allowNull: false,
    comment: '应用密钥'
  },
  merchant_id: {
    type: DataTypes.STRING,
    comment: '商户ID'
  },
  merchant_key: {
    type: DataTypes.STRING,
    comment: '商户密钥'
  },
  notify_url: {
    type: DataTypes.STRING,
    comment: '通知URL'
  },
  access_token: {
    type: DataTypes.STRING,
    comment: '访问令牌'
  },
  access_token_expires_at: {
    type: DataTypes.DATE,
    comment: '访问令牌过期时间'
  },
  qr_code_settings: {
    type: DataTypes.JSON,
    defaultValue: {},
    comment: '二维码设置'
  },
  message_templates: {
    type: DataTypes.JSON,
    defaultValue: [],
    comment: '消息模板'
  },
  is_active: {
    type: DataTypes.BOOLEAN,
    defaultValue: true,
    comment: '是否激活'
  }
}, {
  underscored: true,
  indexes: [
    {
      unique: true,
      fields: ['app_id'],
      comment: '应用ID索引'
    }
  ],
  comment: '微信应用信息表'
});

module.exports = WechatApp; 